package com.example.jobback.util;

import com.example.jobback.config.AuthConfig;
import org.springframework.stereotype.Component;

/**
 * @ClassName: PhoneNumberUtils
 * @Description: 电话号码工具类
 * @Author: lhb
 * @Date: 2025/5/27
 */
@Component
public class PhoneNumberUtils {

    private final AuthConfig authConfig;

    public PhoneNumberUtils(AuthConfig authConfig) {
        this.authConfig = authConfig;
    }

    /**
     * @Description: 手机号加*处理
     * @param phone
     * @return String
     * @Author lhb
     * @CreateTime 2025/7/25 16:19
     */
    public static String maskPhoneNumber(String phone) {
        if (phone == null || phone.length() != 11) {
            return phone; // 如果为空或长度不为11位，返回原值
        }
        return phone.substring(0, 3) + "****" + phone.substring(7);
    }

    /**
     * @Description: 解密手机号
     * @param phoneAes
     * @return String
     * @Author lhb
     * @CreateTime 2025/7/25 16:19
     */
    public String decryptPhone(String phoneAes) throws Exception {
        String phone = SecureEncryptionUtil.decrypt(phoneAes, authConfig.getPhoneSecret());
        return phone;
    }

    /**
     * @Description: 加密手机号
     * @param phone
     * @return String
     * @Author lhb
     * @CreateTime 2025/7/25 16:19
     */
    public String encryptPhone(String phone) throws Exception {
        String phoneAes = SecureEncryptionUtil.encrypt(phone,authConfig.getPhoneSecret());
        return phoneAes;
    }


}
